package com.rc.saas.tenant.service.enterprise;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.mapper.enterprise.RcEnterpriseGainGradeSettingMapper;
import com.rc.saas.tenant.model.enterprise.RcEnterpriseGainGradeSetting;
import com.rc.saas.tenant.model.enterprise.RcEnterpriseGainGradeSettingExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class RcEnterpriseGainGradeSettingServiceImpl implements  RcEnterpriseGainGradeSettingService{

    @Autowired
    private RcEnterpriseGainGradeSettingMapper enterpriseGainGradeSettingMapper;

    @Override
    public RcEnterpriseGainGradeSettingMapper getMapper() {
        return enterpriseGainGradeSettingMapper;
    }

    @Override
    public void batchInsert(List<RcEnterpriseGainGradeSetting> list) {
        enterpriseGainGradeSettingMapper.batchInsert(list);
    }

    @Override
    public void batchUpdate(List<RcEnterpriseGainGradeSetting> list) {
        list.forEach(gradeSetting -> {
            enterpriseGainGradeSettingMapper.updateByPrimaryKeySelective(gradeSetting);
        });
    }

    @Override
    public void batchDelete(List<Long> list) {
        enterpriseGainGradeSettingMapper.batchDelete(list);
    }

    @Override
    public RcEnterpriseGainGradeSetting selectGradeBetweenInterval(Long gainId, BigDecimal money) {
        return enterpriseGainGradeSettingMapper.selectGradeBetweenInterval(gainId, money);
    }

    @Override
    public PageInfo<RcEnterpriseGainGradeSetting> listPageEnterpriseGainGrade(Long gainId, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        RcEnterpriseGainGradeSettingExample example = new RcEnterpriseGainGradeSettingExample();
        example.createCriteria().andEnterpriseGainIdEqualTo(gainId);
        List<RcEnterpriseGainGradeSetting> list = enterpriseGainGradeSettingMapper.selectByExample(example);
        return new PageInfo<>(list);
    }

    @Override
    public List<RcEnterpriseGainGradeSetting> listGradeByGain(Long gainId) {
        RcEnterpriseGainGradeSettingExample example = new RcEnterpriseGainGradeSettingExample();
        example.createCriteria().andEnterpriseGainIdEqualTo(gainId);
        List<RcEnterpriseGainGradeSetting> list = enterpriseGainGradeSettingMapper.selectByExample(example);
        return list;
    }
}
